<html>
<head><meta charset="utf-8"><title>cfg to detect stable / unstable · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html">cfg to detect stable / unstable</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="175816862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175816862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175816862">(Sep 16 2019 at 14:26)</a>:</h4>
<p>is there a way for libcore/libstd macros to detect whether the toolchain is a stable or unstable toolchain ?</p>



<a name="175816921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175816921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175816921">(Sep 16 2019 at 14:27)</a>:</h4>
<p>we currently have a bug in which <code>is_x86_feature_detected!("unstable-target-feature")</code> works on stable</p>



<a name="175816950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175816950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175816950">(Sep 16 2019 at 14:27)</a>:</h4>
<p>that macro looks like:</p>
<div class="codehilite"><pre><span></span><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">is_x86_feature_detected</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="p">(</span><span class="s">&quot;avx&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">  </span><span class="p">(</span><span class="s">&quot;some-unstable-feature&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">  </span><span class="p">(</span><span class="cp">$tt</span>:<span class="nc">tt</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">compile_error</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;unknown target feature: {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="cp">$tt</span><span class="p">)</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="175817090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175817090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175817090">(Sep 16 2019 at 14:29)</a>:</h4>
<p>but I can't place a stability attribute in the macro arms</p>



<a name="175817236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175817236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175817236">(Sep 16 2019 at 14:30)</a>:</h4>
<p>I suppose I could do something like:</p>
<div class="codehilite"><pre><span></span><span class="p">(</span><span class="s">&quot;unstable-feature&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">     </span><span class="cp">#[unstable(...)]</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="n">foo</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>instead</p>



<a name="175818624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175818624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175818624">(Sep 16 2019 at 14:43)</a>:</h4>
<p>but this errors with: error: stability attributes may not be used outside of the standard library</p>



<a name="175818638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175818638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175818638">(Sep 16 2019 at 14:44)</a>:</h4>
<p>apparently because the macro expands code to a user crate that uses the stability attribute</p>



<a name="175818760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175818760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175818760">(Sep 16 2019 at 14:45)</a>:</h4>
<p>(i'm using  <code> #[allow_internal_unstable(staged_api)]</code> on the macro though)</p>



<a name="175831088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175831088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175831088">(Sep 16 2019 at 16:59)</a>:</h4>
<p><code>staged_api</code> AFAIK is a crate-level attribute and has no effect when used elsewhere</p>



<a name="175863555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175863555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175863555">(Sep 16 2019 at 23:48)</a>:</h4>
<p>So I didn't manage to expand the function items in the macro, but I'm expanding a new module inside libstd that contains the functions, and have the macro expand calls to those.</p>



<a name="175863574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175863574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175863574">(Sep 16 2019 at 23:49)</a>:</h4>
<p>However, user code is not failing to compile when using unstable APIs from this module via the macro</p>



<a name="175863577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cfg%20to%20detect%20stable%20/%20unstable/near/175863577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cfg.20to.20detect.20stable.20.2F.20unstable.html#175863577">(Sep 16 2019 at 23:49)</a>:</h4>
<p>:/</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>